package apps

import (
	"github.com/gin-gonic/gin"
	ginSwagger "github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
	"net/http"
	"server/global"
	"server/middleware"
)

func InitRouters() *gin.Engine {
	Router := gin.Default()
	xidwRouter := RouterGroupApp.Xidw

	Router.StaticFS(global.XidwConfig.Local.StorePath, http.Dir(global.XidwConfig.Local.StorePath))

	Router.GET(global.XidwConfig.System.RouterPrefix+"/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	global.Logger.Info("register swagger handler")

	PublicGroup := Router.Group(global.XidwConfig.System.RouterPrefix)
	{
		PublicGroup.GET("/health", func(c *gin.Context) {
			c.JSON(http.StatusOK, "ok")
		})
	}
	{
		xidwRouter.InitBaseRouter(PublicGroup)
	}
	PrivateGroup := Router.Group(global.XidwConfig.System.RouterPrefix)
	PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
	{
		xidwRouter.InitApiRouter(PrivateGroup)
		xidwRouter.InitJwtRouter(PrivateGroup)
		xidwRouter.InitUserRouter(PrivateGroup)
		xidwRouter.InitMenuRouter(PrivateGroup)
		xidwRouter.InitSystemRouter(PrivateGroup)
		xidwRouter.InitCasbinRouter(PrivateGroup)
		xidwRouter.InitAuthorityRouter(PrivateGroup)
		xidwRouter.InitSysDictionaryRouter(PrivateGroup)
		xidwRouter.InitSysOperationRecordRouter(PrivateGroup)
		xidwRouter.InitSysDictionaryDetailRouter(PrivateGroup)
		xidwRouter.InitAuthorityBtnRouterRouter(PrivateGroup)
		xidwRouter.InitFileUploadAndDownloadRouter(PrivateGroup)

	}
	{
		odsRouter := RouterGroupApp.Ods

		odsRouter.InitOdsSupplierRouter(PrivateGroup)
		odsRouter.InitOdsDbTableRouter(PrivateGroup)
		odsRouter.InitOdsOdbRouter(PrivateGroup)
		odsRouter.InitOdsDbFieldRouter(PrivateGroup)
		odsRouter.InitOdsJobRouter(PrivateGroup)
		odsRouter.InitOdsDbSyncLogRouter(PrivateGroup)
		odsRouter.InitOdsDbConfigRouter(PrivateGroup)
		odsRouter.InitOdsFtpRouter(PrivateGroup)
		odsRouter.InitOdsKafkaRouter(PrivateGroup)
		odsRouter.InitDbFldMapRouter(PrivateGroup)

	}
	{
		adsRouter := RouterGroupApp.Ads
		adsRouter.InitAdsApiRouter(PrivateGroup)
		adsRouter.InitAdsConfigRouter(PrivateGroup)
		adsRouter.InitAdsTopicRouter(PrivateGroup)
		adsRouter.InitAdsFldRouter(PrivateGroup)

	}
	{
		dmRouter := RouterGroupApp.Dm

		dmRouter.InitDmSchemaRouter(PrivateGroup)
	}
	{
		dwsRouter := RouterGroupApp.Dws

		dwsRouter.InitDwsTopicRouter(PrivateGroup)
		dwsRouter.InitDwsApiRouter(PrivateGroup)
		dwsRouter.InitDwsFldRouter(PrivateGroup)
		dwsRouter.InitDwsTbRouter(PrivateGroup)
		dwsRouter.InitDwsConfigRouter(PrivateGroup)
	}
	{
		udsRouter := RouterGroupApp.Uds

		udsRouter.InitUdsFldRouter(PrivateGroup)
		udsRouter.InitUdsTbRouter(PrivateGroup)
	}

	global.Logger.Info("router register success")
	return Router
}
